package ali_oss

import (
	"bytes"
	"context"
	"io/ioutil"
	"mime/multipart"
)

var ImgAllowExts = map[string]bool{
	".jpg":  true,
	".png":  true,
	".gif":  true,
	".jpeg": true,
}

func UploadFile(ctx context.Context, key string, fileHandle multipart.File) error {
	cli, err := NewClient()
	if err != nil {
		return err
	}
	fileByte, err := ioutil.ReadAll(fileHandle) //获取上传文件字节流
	if err != nil {
		return err
	}
	bucket, err := cli.Bucket(NearbyBucket)
	return bucket.PutObject(key, bytes.NewReader(fileByte))
}
